/********************************************************************
	Rhapsody	: 7.5 
	Login		: KBE
	Component	: DefaultComponent 
	Configuration 	: ClientCodeConfig
	Model Element	: RequestPatient
//!	Generated Date	: Sun, 23, Sep 2012  
	File Path	: DefaultComponent\ClientCodeConfig\RequestPatient.cpp
*********************************************************************/

//## auto_generated
#include "RequestPatient.h"
//## auto_generated
#include "Reactor.h"
//## package Default
#include "..\StopWatch.h"

//## class RequestPatient
RequestPatient::RequestPatient(Reactor * reactor) {
    //#[ operation RequestPatient(Reactor *)
    //#[ operation LogEvent(Reactor*,SOCK_Stream)
    //setPeer_stream_(stream);
    //handle = (HANDLE)stream->get_handle();
    itsReactor = reactor;
    //itsReactor->registerHandler(*this, READ_EVENT);
    //#]
}

RequestPatient::RequestPatient() {
	state_ = 1;
}

RequestPatient::~RequestPatient() {
	delete peer_stream_;
}

void RequestPatient::getPatientInfo()
{
	StopWatch *sw1 = new StopWatch();

	printf("Input CPR > ");
	scanf("%s", buffer_);
	sw1->start();
	getPeer_stream_()->send_n(buffer_, 100, 0);
	sw1->split("Patient Info Requested");

}

void RequestPatient::handleEvent(HANDLE h, Event_Type& et) {
    //#[ operation handleEvent(HANDLE,Event_Type)
	if (et == type) {
    	int n = getPeer_stream_()->recv_n(buffer_, sizeof(buffer_), 0);
    	if (n > 0) { 
    		PatientAction();
    	}
    	else 
    	{
    		//itsReactor->removeHandler(*this, type);
    		//delete this; // Deallocate ourselves
    	}
	}
    //#]
}

void RequestPatient::PatientAction() {
    //#[ operation PatientAction()
    printf("Patient: %s\n", buffer_);
    //#]
}

char RequestPatient::getBuffer_(int i1) const {
    return buffer_[i1];
}

void RequestPatient::setBuffer_(int i1, char p_buffer_) {
    buffer_[i1] = p_buffer_;
}

/*********************************************************************
	File Path	: DefaultComponent\ClientCodeConfig\RequestPatient.cpp
*********************************************************************/
